<?php include("../../includes/includes.php"); ?>
<?php
connect($config);

$trades = "OFF";
$timeLimit = "OFF";
$bot = "OFF";
$timeLength = "24";
$tradesPageID = null;
$picksPageID = null;
$seasonInProgress = "NO";
$forumID = null;
$fullLockoutPenalty = null;
$partialLockoutPenalty = null;

$loggedInTeam = getLoggedInTeam();

if (Admin::isAuthentic($loggedInTeam->coachName)) {
	if (isset($_POST['trades']) && $_POST['trades'] != null && $_POST['trades'] != '') {
		$trades=$_POST['trades'];
	}
	if (isset($_POST['timeLimit']) && $_POST['timeLimit'] != null && $_POST['timeLimit'] != '') {
		$timeLimit=$_POST['timeLimit'];
	}
	if (isset($_POST['bot']) && $_POST['bot'] != null && $_POST['bot'] != '') {
		$bot=$_POST['bot'];
	}
	
	if (isset($_POST['timeLength']) && $_POST['timeLength'] != null && $_POST['timeLength'] != '') {
		$timeLength=$_POST['timeLength'];
	}
	
	if (isset($_POST['tradesPageID']) && $_POST['tradesPageID'] != null && $_POST['tradesPageID'] != '') {
		$tradesPageID=$_POST['tradesPageID'];
	}
	
	if (isset($_POST['picksPageID']) && $_POST['picksPageID'] != null && $_POST['picksPageID'] != '') {
		$picksPageID=$_POST['picksPageID'];
	}			
	
	if (isset($_POST['seasonInProgress']) && $_POST['seasonInProgress'] != null && $_POST['seasonInProgress'] != '') {
		$seasonInProgress=$_POST['seasonInProgress'];
	}	

	if (isset($_POST['submittedTeamsPageID']) && $_POST['submittedTeamsPageID'] != null && $_POST['submittedTeamsPageID'] != '') {
		$submittedTeamsPageID=$_POST['submittedTeamsPageID'];
	}
	
	if (isset($_POST['resultsPageID']) && $_POST['resultsPageID'] != null && $_POST['resultsPageID'] != '') {
		$resultsPageID=$_POST['resultsPageID'];
	}
	
	if (isset($_POST['forumID']) && $_POST['forumID'] != null && $_POST['forumID'] != '') {
		$forumID=$_POST['forumID'];
	}
	
	if (isset($_POST['fullLockoutPenalty']) && $_POST['fullLockoutPenalty'] != null && $_POST['fullLockoutPenalty'] != '') {
		$fullLockoutPenalty=$_POST['fullLockoutPenalty'];
	}
	
	if (isset($_POST['partialLockoutPenalty']) && $_POST['partialLockoutPenalty'] != null && $_POST['partialLockoutPenalty'] != '') {
		$partialLockoutPenalty=$_POST['partialLockoutPenalty'];
	}
	
	updateSystemSettings($trades, $timeLimit, $bot, $timeLength, $tradesPageID, $picksPageID, $seasonInProgress, $submittedTeamsPageID, $resultsPageID, $forumID, $fullLockoutPenalty, $partialLockoutPenalty, $loggedInTeam->leagueId);
}

$reviewsPerPage = -1;
if (isset($_POST['reviewsPerPage']) && $_POST['reviewsPerPage'] != null) {
	$reviewsPerPage = $_POST['reviewsPerPage'];
}
$usePreferences = "DONT_USE";
if (isset($_POST['usePreferences']) && $_POST['usePreferences'] != null) {
	$usePreferences=$_POST['usePreferences'];
}

if (isset($_POST['teamName']) && $_POST['teamName'] != "") {
	updateTeamName($loggedInTeam->id, str_replace("'", "''", $_POST['teamName']));
}
$draftTab = "NO";
if (isset($_POST['draftTab']) && $_POST['draftTab'] != null) {
	$draftTab = $_POST['draftTab'];
}
$prefTab = "NO";
if (isset($_POST['prefTab']) && $_POST['prefTab'] != null) {
	$prefTab = $_POST['prefTab'];
}
$archiveTab = "NO";
if (isset($_POST['archiveTab']) && $_POST['archiveTab'] != null) {
	$archiveTab=$_POST['archiveTab'];
}
$statusTab = "NO";
if (isset($_POST['statusTab']) && $_POST['statusTab'] != null) {
	$statusTab=$_POST['statusTab'];
}
$overviewTab = "NO";
if (isset($_POST['overviewTab']) && $_POST['overviewTab'] != null) {
	$overviewTab=$_POST['overviewTab'];
}

updateUserSettings($_POST['coachName'], $_POST['tradesPerPage'], $reviewsPerPage, $usePreferences, $draftTab, $prefTab, $archiveTab, $statusTab, $overviewTab, $loggedInTeam->leagueId);
mysql_close();

header( 'Location: ../home/homePage.php' );
?>